package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by XCKJ_Paladowow on 2016/3/17.
 */
public class SellerListTask extends CouponHttpBaseTask {
    private int mSize;
    private int mPageNo;
    private String mFoodid;
    private String mAreaid;
    private static final String SELLERLIST = "businessList";

    public SellerListTask(int size, int pageNo, String foodid, String areaid) {
        super(TaskType.SELLERLIST_TASK);
        mSize = size;
        mPageNo = pageNo;
        mFoodid = foodid;
        mAreaid = areaid;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        JSONObject jsonString = null;
        if (respJson != null) {
            jsonString = respJson.getJSONObject(SELLERLIST);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, jsonString);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(RequestType.SELLERLIST_REQUEST);
            JSONObject json = new JSONObject();
            json.put("size", mSize);
            json.put("pageNo", mPageNo);
            json.put("foodId", mFoodid);
            json.put("areaId",mAreaid);
            request.setData(json.toString());
//            request.setApiNo(ApiNo.SELLERLIST);
            addRequest(request);
        }
    }
}
